package cn.com.jcoo.config;

import cn.com.jcoo.ehcahce.SaTokenEhcacheManager;
import cn.com.jcoo.satoken.SaTokenEhcacheDao;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@EnableConfigurationProperties(SaTokenCacheProperties.class)
public class SaTokenEhcacheAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "sa-token.cache", name = "type", havingValue = "ehcache")
    public SaTokenEhcacheManager saTokenEhcacheManager(SaTokenCacheProperties saTokenCacheProperties) {
        return new SaTokenEhcacheManager(saTokenCacheProperties);
    }

    @Bean
    @ConditionalOnBean(SaTokenEhcacheManager.class)
    public SaTokenEhcacheDao saTokenEhcacheDao(SaTokenEhcacheManager saTokenEhcacheManager) {
        return new SaTokenEhcacheDao(saTokenEhcacheManager);
    }
}
